package com.blacksheep.mtm.controller;

import com.blacksheep.mtm.common.utils.ResultUtil;
import com.blacksheep.mtm.pojo.common.DataTablesResult;
import com.blacksheep.mtm.pojo.common.Result;
import com.blacksheep.mtm.service.OrderReviewService;
import com.blacksheep.mtm.service.WxOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api("微信订单列表")
public class WxOrderController {

    @Autowired
    private WxOrderService wxOrderService;
    @RequestMapping(value = "/order/wx/list",method = RequestMethod.GET)
    @ApiOperation(value = "获取订单列表")
    public DataTablesResult getOrderList(int draw, int start, int length, String searchKey, int[] state,
                                         String minDate, String maxDate,
                                         @RequestParam("search[value]") String search,
                                         @RequestParam("order[0][column]") int orderCol,
                                         @RequestParam("order[0][dir]") String orderDir){

        //获取客户端需要排序的列
        String[] cols = {"checkbox","id", "order_content","member_name","state", "a.create_time"};
        String orderColumn = cols[orderCol];
        //默认排序列
        if(orderColumn == null) {
            orderColumn = "a.create_time";
        }
        //获取排序方式 默认为desc(asc)
        if(orderDir == null) {
            orderDir = "desc";
        }
        if (!StringUtils.isBlank(search)){
            searchKey =search;
        }
        DataTablesResult result= wxOrderService.getList(draw,start,length,state,searchKey,minDate,maxDate,orderColumn,orderDir);
        return result;
    }


    @RequestMapping(value = "/order/wx/cancel",method = RequestMethod.POST)
    @ResponseBody
    public Result<Integer> getIceBoxByCode(long id){
        int result =wxOrderService.updateState(id,-1);
        return new ResultUtil<Integer>().setData(result);
    }
}
